<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
    <section class="content-header">
    <h1>设备重量、设计工时确认信息明细</h1>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <form id="queryForm" onsubmit="return false">
                            <input name="designType" type="hidden" th:value="${ProjectCostModel.designType}">
                            <input name="inputId" type="hidden" th:value="${ProjectCostModel.inputId}">
                            <input  name="partName" type="hidden" th:value="${ProjectCostModel.partName}">
                            <input name="dCostKind" type="hidden" th:value="${ProjectCostModel.costKind}">
                            <input name="kbId" type="hidden" th:value="${ProjectCostModel.fkId}">
                            <input name="kbCode" type="hidden" th:value="${ProjectCostModel.code}">
                            <div class="row">
                                <div class="form-inline">
                                    <div class="form-group" style="margin-right: 10px">
                                        <label>项目编号：</label>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:text="${ProjectCostModel.code}"></span>
                                    </div>
                                    <div class="form-group" style="margin-right: 10px">
                                        <label>项目名称：</label>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:text="${ProjectCostModel.name}"></span>
                                    </div>
                                    <div class="form-group" style="margin-right: 10px">
                                        <label>项目数量：</label>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:text="${ProjectCostModel.num}"></span>
                                    </div>
                                    <div class="form-group" style="margin-right: 10px">
                                        <label>设备部分：</label>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:text="${ProjectCostModel.partName}"></span>
                                    </div>
                                    <div class="form-group" style="margin-right: 10px">
                                        <label>专业：</label>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:if="${ProjectCostModel.designType==1}">机械</span>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:if="${ProjectCostModel.designType==2}">自动化</span>
                                        <span class="form-control"
                                              style="border: none;border-bottom: solid 1px #eee;width: 300px;text-align: center;"
                                              th:if="${ProjectCostModel.designType==3}">流体</span>
                                    </div>
                                    <input name="designType" type="hidden" th:value="${ProjectCostModel.designType}">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div id="toolbar1" class="row">
                        <div style="height: 20px"></div>
                        <a  style="margin-right: 10px"
                           id="btn_add1" class="btn btn-info">
                            <span class="Bold">人工工时添加</span>
                        </a>
                        <a href="javascript:void(0);"
                           style="margin-right: 10px"
                           class="btn btn-danger"
                           onclick="delDesHours()">
                            <span class="Bold">数据清空</span>
                        </a>
                    </div>
                    <div class="box-body">
                        <table id="bootstrap-table1"
                               style="table-layout: fixed;word-break: break-all;word-wrap: break-word;"></table>
                    </div>
                    <div id="toolbar2" class="row">
                        <div style="height: 100px"></div>
                        <a style="margin-right: 10px"
                           id= "btn_add2" class="btn  btn-info">
                            <span class="Bold">设备重量添加</span>
                        </a>
                        <a href="javascript:void(0);"
                           class="btn btn-danger"
                           style="margin-right: 10px"
                           onclick="delDesWeight()">
                            <span class="Bold">数据清空</span>
                        </a>
                    </div>
                    <div class="box-body">
                        <table id="bootstrap-table2"
                               style="table-layout: fixed;word-break: break-all;word-wrap: break-word"></table>
                    </div>
                </div>
            </div>
        </div>
        <!--添加人工工时模态框-->
        <div class="modal fade" id="modal-work-hours-add">
            <div class="modal-dialog" style="width: 500px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">人工工时编辑</h4>
                    </div>
                    <div class="modal-body">
                        <form id="workForm" class="form-horizontal">
                            <div class="col-md-12">
                                <input id="desId" name="desId" type="hidden">
                                <input name="dName" value="1" type="hidden">
                                <input name="designType" type="hidden">
                                <input name="inputId" type="hidden">
                                <input name="partName" type="hidden">
                                <input name="dCostKind" type="hidden">
                                <input name="kbId" type="hidden">
                                <input name="kbCode" type="hidden">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">工时类别</label>
                                    <div class="col-sm-6">
                                        <input type="hidden" class="form-control" name="desHours" id="desHours">
                                        <select name="desCode" class="form-control" id="hours">
                                            <option value="design">设计工时</option>
                                            <option value="debug">调试工时</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">数量</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="desNum">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">单位</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="desUnit">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">备注</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="desRemark">
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-info" id="btn-create-hours">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--添加设备重量模态框-->
        <div class="modal fade" id="modal-facility-weight-add">
            <div class="modal-dialog" style="width: 500px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">设备重量编辑</h4>
                    </div>
                    <div class="modal-body">
                        <form id="weightForm" class="form-horizontal">
                           <div class="col-md-12">
                               <input id="weiId" name="weiId" type="hidden">
                               <input name="dName" value="2" type="hidden">
                               <input name="designType" type="hidden">
                               <input name="inputId" type="hidden">
                               <input name="partName" type="hidden">
                               <input name="wCostKind" type="hidden">
                               <input name="kbId" type="hidden">
                               <input name="kbCode" type="hidden">
                               <div class="form-group">
                                   <label class="col-sm-4 control-label">材质名称</label>
                                   <div class="col-sm-6">
                                       <input type="hidden" class="form-control" name="weiMaterial" id="weiMaterial">
                                       <select name="weiWeightType" class="form-control" id="weight">
                                           <option value="0">设备总重</option>
                                           <option value="1">结构净重：碳钢</option>
                                           <option value="2">结构净重：不锈钢</option>
                                           <option value="3">结构净重：铝材</option>
                                           <option value="4">结构净重：其他</option>
                                       </select>
                                   </div>
                               </div>
                           </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">主要辅材重量</label>
                                    <div class="col-sm-6">
                                        <input th:type="text" class="form-control" name="weiNum">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">单位</label>
                                    <div class="col-sm-6">
                                        <input th:type="text" class="form-control" name="weiUnit">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">备注</label>
                                    <div class="col-sm-6">
                                        <input th:type="text" class="form-control" name="weiRemark">
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn  btn-info" id="btn-create-weight">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table1;
    var table2;

    /**打开设计工时编辑模态框,回显数据*/
    function designEdit(desId){
        debugger
        js.post({
            url: ctx + "dataEntry/designTime/showHours",
            data:{
                desId:desId
            },
            success:function (result) {
                $("#workForm").fillData(result);
                js.modal.open("modal-work-hours-add");
            }
        })
    }
    // function designEdit(desId){
    //debugger
    //     $("#workForm").fillData(desId);
    //     js.modal.open("modal-work-hours-add");
    // }

    /**打开设备重量编辑模态框,回显数据*/
    function weightEdit(weiId){
        debugger
        js.post({
            url: ctx + "dataEntry/designTime/showWeight",
            data:{
                weiId:weiId
            },
            success:function (result) {
                $("#weightForm").fillData(result);
                js.modal.open("modal-facility-weight-add");
            }
        })
    }
    // function weightEdit(weiId){
    //     debugger
    //     $("#weightForm").fillData(weiId);
    //     js.modal.open("modal-facility-weight-add");
    // }

    /**设计工时删除*/
    function designErase(desId){
        js.modal.confirm("确认删除该条设计工时信息吗？",function () {
            debugger
            js.post({
                url: ctx + "dataEntry/designTime/delHours",
                //date赋值：{参数-对应model定义：方法临时参数-只在方法里起作用}
                data:{
                    desId:desId
                },
                success:function(result){
                    if(result.type === web_status.SUCCESS){
                        js.modal.success(result.msg);
                        js.table.refresh(table1);
                    }else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /**设备重量删除*/
    function weightErase(weiId){
        js.modal.confirm("确认删除该条设备重量信息吗？",function () {
            debugger
            js.post({
                url: ctx + "dataEntry/designTime/delWeight",
                //date赋值：{参数-对应model定义：方法临时参数-只在方法里起作用}
                data:{
                    weiId:weiId
                },success:function(result){
                    if(result.type === web_status.SUCCESS){
                        js.modal.success(result.msg);
                        js.table.refresh(table2);
                    }else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /**工时数据清除（全部）*/
    function delDesHours(){
        js.modal.confirm("确定清空所有设计工时数据吗？",function (){
            debugger
            js.submit({
                data: new FormData($("#queryForm")[0]),
                url: ctx +  "dataEntry/designTime/DesHoursDel",
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table1);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
    }

    /**重量数据清除（全部）*/
    function delDesWeight(){
        js.modal.confirm("确定清空所有设备重量数据吗？",function (){
            debugger
            js.submit({
                data: new FormData($("#queryForm")[0]),
                url: ctx + "dataEntry/designTime/DesWeightDel",
                success:function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table2);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
    }

    $(function () {
        //加载列表数据——人工工时列表

        table1=js.table.init({
            id:'bootstrap-table1',
            url:ctx + "dataEntry/designTime/design",
            showColumns: false,
            showExport: false,
            pagination: true,
            pageSize: 10,
            striped: true,
            columns:[
                {
                    title:'序号',field:'desId',width:'60',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title:'工时类别',field:'desHours'},
                {title:'数量',field:'desNum'},
                {title:'单位',field:'desUnit'},
                {title:'备注',field:'desRemark'},
                {title:'填报人',field:'desInputUser'},
                {title:'填报时间',field:'desEditDate'},
                {title:'接收状态',field:'desReceiveFlag',
                    formatter: function (value, row, index) {
                        if (value === 0){
                            return '未接收';
                        } else if (value === 1){
                            return '已接收';
                        }
                    }
                },
                {
                    title:'操作',
                    formatter: function (value, row, index){
                        debugger
                       var actions = [];
                        if (row.desReceiveFlag === 0){
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="designEdit(' + row.desId + ')">编辑</a> ');
                            // actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="designEdit(' + js.jsonStringify(row)+ ')">编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="designErase(' + row.desId + ')">删除</a>')
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        // $("#btn-search").on('click',function () {
        //     js.table.search(table1);
        // })

        //加载列表数据——设备重量

        table2=js.table.init({
            id:'bootstrap-table2',
            url:ctx + "dataEntry/designTime/weight",
            toolbar: "toolbar2",
            showColumns: false,
            showExport: false,
            pagination: true,
            pageSize: 30,
            striped: true,
            columns:[
                {
                    title:'序号',field:'weiId',width:'60',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title:'材质名称',field:'weiMaterial'},
                {title:'主要辅材用量',field:'weiNum'},
                {title:'单位',field:'weiUnit'},
                {title:'备注',field:'weiRemark'},
                {title:'填报人',field:'weiInputUser'},
                {title:'填报时间',field:'weiEditDate'},
                {title:'接收状态',field:'weiReceiveFlag',
                    formatter: function (value, row, index){
                        if (value === 0){
                            return '未接收';
                        } else if (value === 1){
                            return '已接收';
                        }
                    }
                },
                {title:'操作',
                    formatter: function (value, row, index) {
                        debugger
                        var actions = [];
                        if (row.weiReceiveFlag === 0){
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="weightEdit(' + row.weiId + ')">编辑</a> ');
                            // actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="weightEdit(' + js.jsonStringify(row)+ ')">编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="weightErase(' + row.weiId + ')">删除</a> ');
                        }
                        return actions.join('');
                    }
                }

            ]
        });
        /**
         * 表格搜索
         */
        // $("#btn-search").on('click',function () {
        //     js.table.search(table2);
        // });
        /***
         * 打开人工工时数据模态框
         */
        $("#btn_add1").on('click', function () {
            $("#workForm input[name='dName']").val(1);
            $("#workForm input[name='designType']").val($("#queryForm input[name='designType']").val());
            $("#workForm input[name='inputId']").val($("#queryForm input[name='inputId']").val());
            $("#workForm input[name='partName']").val($("#queryForm input[name='partName']").val());
            $("#workForm input[name='dCostKind']").val($("#queryForm input[name='dCostKind']").val());
            $("#workForm input[name='kbId']").val($("#queryForm input[name='kbId']").val());
            $("#workForm input[name='kbCode']").val($("#queryForm input[name='kbCode']").val());
            js.modal.open("modal-work-hours-add")
        });


        /**
         * 设计工时模态框保存
         */
        $("#btn-create-hours").on('click',function () {

            $("#desHours").val($("#hours").find("option:selected").text());
            js.submit({
                url:ctx +"dataEntry/designTime/hoursWeightSave",
                data:new FormData($("#workForm")[0]),
                success:function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table1);
                        js.modal.hide("modal-work-hours-add");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

        /**
         *打开设备重量数据模态框
         */
        $("#btn_add2").on('click', function () {
            $("#weightForm input[name='dName']").val(2);
            $("#weightForm input[name='designType']").val($("#queryForm input[name='designType']").val());
            $("#weightForm input[name='inputId']").val($("#queryForm input[name='inputId']").val());
            $("#weightForm input[name='partName']").val($("#queryForm input[name='partName']").val());
            $("#weightForm input[name='wCostKind']").val($("#queryForm input[name='dCostKind']").val());
            $("#weightForm input[name='kbId']").val($("#queryForm input[name='kbId']").val());
            $("#weightForm input[name='kbCode']").val($("#queryForm input[name='kbCode']").val());
            js.modal.open("modal-facility-weight-add")
        });

        /**
         * 设备重量模态框保存
         */
        $("#btn-create-weight").on('click',function () {

            $("#weiMaterial").val($("#weight").find("option:selected").text());
            js.submit({
                url:ctx +"dataEntry/designTime/hoursWeightSave",
                data:new FormData($("#weightForm")[0]),
                success:function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table2);
                        js.modal.hide("modal-facility-weight-add");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

        /** 初始化验证 */
        js.validate.init("workForm",{
            fields:{
                desNum:{
                    validators:{
                        notEmpty:{message:'请输入数量'}
                    }
                },
                desUnit:{
                    validators:{
                        notEmpty:{message:'请输入单位'}
                    }
                }
            }
        });

        /**
         * 隐藏设计工时模态框 modal-work-hours-add
         */
        js.modal.hideEvent("modal-work-hours-add", function () {
            js.reset("workForm");
        });

        /**
         * 隐藏设备重量模态框 modal-facility-weight-add
         */
        js.modal.hideEvent("modal-facility-weight-add", function () {
            js.reset("weightForm");
        });
    })
</script>
</body>
</html>